﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using NNS.Framework;
using QLTB.BusinessLayer;
using QLTB.BusinessObjects;
using QLTB.DataAccess;
using QLTB.LinhKien.UI;
using QLTB.LichSu.UI;
using NNS.Enumeration;
using DevExpress.XtraGrid.Views.Grid;
using NNS.UI;
using QLTB.Common;

namespace QLTB.ThietBi.UI
{
    public partial class frmThietBi : DevExpress.XtraEditors.XtraForm,IBase
    {
        EditMode mode;
        public event SaveChangedEventHander SaveChanged;
        public event SaveChangingEventHander SaveChanging;
        public event SaveCompleteEventHander SaveComplete;

        public void OnSaveChanged(SaveChangedEventArgs e)
        {
            SaveChangedEventHander changed = SaveChanged;
            if (changed != null) changed(this, e);
        }

        public void OnSaveChanging(SaveChangingEventArgs e)
        {
            SaveChangingEventHander changing = SaveChanging;
            if (changing != null) changing(this, e);
        }

        public void OnSaveComplete(SaveCompleteEventArgs e)
        {
            SaveCompleteEventHander complete = SaveComplete;
            if (complete != null) complete(this, e);
        }


        private bool _notsave;
        public bool NotSave
        {
            get { return _notsave; }
            set
            {
                _notsave = value;
                OnSaveChanged(new SaveChangedEventArgs() {NotSave = value});
            }
        }

        public frmThietBi()
        {
            mode = new EditMode();
            mode = EditMode.None;

            InitializeComponent();
            TBL_quyenBL.IgnoreError = true;
            if (!TBL_quyenBL.isTaomoi(EnumComponent.iProvider))
            {
                gbList.OptionsView.NewItemRowPosition = NewItemRowPosition.None;
            }
            TBL_quyenBL.IgnoreError = false;
           // dsThietBi.TBL_THIETBI.TBL_THIETBIRowChanging += new QLTB.ThietBi.Entity.dsThietBi.TBL_THIETBIRowChangeEventHandler(TBL_THIETBI_TBL_THIETBIRowChanging);
            dsThietBi.TBL_THIETBI.TBL_THIETBIRowChanged += new QLTB.ThietBi.Entity.dsThietBi.TBL_THIETBIRowChangeEventHandler(TBL_THIETBI_TBL_THIETBIRowChanged);
            if (MyLogin.Original.toantinh)
            {
                txtDonvi.Enabled = true;
                MaDonViLookUpEdit.Enabled = true;
                colMaDonVi.Visible = true;
            }
            NotSave = false;
            SaveChanged += new SaveChangedEventHander(frmThietBi_SaveChanged);
            SaveChanging += new SaveChangingEventHander(frmThietBi_SaveChanging);
            SaveComplete += new SaveCompleteEventHander(frmThietBi_SaveComplete);
        }

        void frmThietBi_SaveComplete(object sender, SaveCompleteEventArgs e)
        {
            MyRibbon.ShowProcess = BarItemVisibility.Never;
        }

        void frmThietBi_SaveChanging(object sender, SaveChangingEventArgs e)
        {
            MyRibbon.SetValue(e.Percent);    
        }

        void frmThietBi_SaveChanged(object sender, SaveChangedEventArgs e)
        {
            if (e.NotSave)
            {
                MyRibbon.iSave.ImageIndex = 69;
                this.Text = "Quản lý thiết bị (*)";
                //this.Appearance.ForeColor = Color.Red;
            }
            else
            {
                MyRibbon.iSave.ImageIndex = 24;
                this.Text = "Quản lý thiết bị";
            }

            //throw new NotImplementedException();
        }

        void TBL_THIETBI_TBL_THIETBIRowChanged(object sender, QLTB.ThietBi.Entity.dsThietBi.TBL_THIETBIRowChangeEvent e)
        {
            //throw new NotImplementedException();

            if (mode == EditMode.Load) return;
            if (mode == EditMode.Update) return;

            if (e.Action == DataRowAction.Change)
            {

                Cursor.Current = Cursors.WaitCursor;
                //if (e.Row.RowState == DataRowState.Modified)
                {
                    if (!TBL_quyenBL.isThaydoi(EnumComponent.iEquipment))
                    {

                        Nap();
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                }

                NotSave = true;

                Cursor.Current = Cursors.Default;
            }
            else if (e.Action==DataRowAction.Add)
            {
                NotSave = true;
                Save();
            }
        }

        private void frmThietBi_Load(object sender, EventArgs e)
        {
          
            NapInfo();
        }

        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);
            if (MyRibbon != null)
            {
                MyRibbon.MyRibbon.SetPopupContextMenu(this, MyRibbon.pm);
                
            }
        }

        private void RemoveEvent()
        {
            MyRibbon.iFilter.Checked = gbList.OptionsView.ShowAutoFilterRow;
            MyRibbon.iFilter.ItemClick -= iFilter_ItemClick;
            MyRibbon.iClose.ItemClick -= iClose_ItemClick;
            MyRibbon.iSave.ItemClick -= iSave_ItemClick;
            MyRibbon.iRefesh.ItemClick -= iRefesh_ItemClick;
            MyRibbon.iCopy.ItemClick -= iCopy_ItemClick;
            MyRibbon.iSelectAll.ItemClick -= iSelectAll_ItemClick;
            MyRibbon.iClear.ItemClick -= iClear_ItemClick;
            MyRibbon.iDelete.ItemClick -= iDelete_ItemClick;
            MyRibbon.iDuplicate.ItemClick -= iDuplicate_ItemClick;
            MyRibbon.iComponents.ItemClick -= iComponents_ItemClick;
            MyRibbon.iEquipHistory.ItemClick -= iEquipHistory_ItemClick;
        }

        private void AddEvent()
        {
            MyRibbon.iFilter.Checked = gbList.OptionsView.ShowAutoFilterRow;
            MyRibbon.iFilter.ItemClick += iFilter_ItemClick;
            MyRibbon.iClose.ItemClick += iClose_ItemClick;
            MyRibbon.iSave.ItemClick += iSave_ItemClick;
            MyRibbon.iCancel.ItemClick += iCancel_ItemClick;
            MyRibbon.iRefesh.ItemClick += iRefesh_ItemClick;
            MyRibbon.iCopy.ItemClick += iCopy_ItemClick;
            MyRibbon.iSelectAll.ItemClick += iSelectAll_ItemClick;
            MyRibbon.iClear.ItemClick += iClear_ItemClick;
            MyRibbon.iDelete.ItemClick += iDelete_ItemClick;
            MyRibbon.iDuplicate.ItemClick+=iDuplicate_ItemClick;
            MyRibbon.iComponents.ItemClick+=iComponents_ItemClick;
            MyRibbon.iEquipHistory.ItemClick+=iEquipHistory_ItemClick;
            
        }

        void iDuplicate_ItemClick(object sender, ItemClickEventArgs e)
        {
            //throw new NotImplementedException();
            if (!Visible) return;
            TBL_THIETBIDA da = new TBL_THIETBIDA();
            DataTable dt = dsThietBi.TBL_THIETBI;
            if (dt.GetChanges(DataRowState.Deleted)!=null)
            {
                MyBox.ShowWarning("Dữ liệu hiện tại chưa được lưu!\nVui lòng lưu lại trước khi Copy Cấu hình", "Quản lý thiết bị");
                return;
            }
            da.Duplicate((int)(dt.Rows[gbList.GetFocusedDataSourceRowIndex()]["ID"]));
          
            Nap();
        }

        void iFilter_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!Visible) return;
            gbList.OptionsView.ShowAutoFilterRow = MyRibbon.iFilter.Checked;
        }

        private frmDetail detail;
        void iEquipHistory_ItemClick(object sender, ItemClickEventArgs e)
        {
           
            if (!Visible) return;
            Cursor.Current = Cursors.WaitCursor;
            MyRibbon.iEquipHistory.Enabled = false;
            if (!TBL_quyenBL.isXem(EnumComponent.iEquipHistory))
            {
                MyRibbon.iEquipHistory.Enabled = true;
                Cursor.Current = Cursors.Default;
                return;
            }


            if (detail == null)
            {
                detail = new frmDetail();
            }

            object _ob = gbList.GetFocusedRowCellValue(colID);
            if (_ob == null)
            {
                MyRibbon.iEquipHistory.Enabled = true;
                Cursor.Current = Cursors.Default;
                return;
            }
            var thietbi = new TBL_THIETBIDA().Get((int)_ob);
            if (thietbi == null)
            {
                MyRibbon.iEquipHistory.Enabled = true;
                Cursor.Current = Cursors.Default;
                return;
            }
            detail.ThietBi = thietbi;
            detail.Set(frmDetail.InfoStyle.LS);

            MyRibbon.iEquipHistory.Enabled = true;
            Cursor.Current = Cursors.Default;
            detail.ShowDialog(this);
        }

        void iComponents_ItemClick(object sender, ItemClickEventArgs e)
        {
           
            if (!Visible) return;

            Cursor.Current = Cursors.WaitCursor;
            MyRibbon.iComponents.Enabled = false;
            if (!TBL_quyenBL.isXem(EnumComponent.iComponents))
            {
                Cursor.Current = Cursors.Default;
                MyRibbon.iComponents.Enabled = true;
                return;
            }

            if (detail == null)
            {
                detail = new frmDetail();
            }

            object _ob = gbList.GetFocusedRowCellValue(colID);
            if (_ob == null)
            {
                MyRibbon.iComponents.Enabled = true;
                Cursor.Current = Cursors.Default;
                return;
            }
            var thietbi = new TBL_THIETBIDA().Get((int)_ob);
            if (thietbi == null)
            {
                MyRibbon.iComponents.Enabled = true;
                Cursor.Current = Cursors.Default;
                return;
            }

            detail.ThietBi = thietbi;
            detail.Set(frmDetail.InfoStyle.LK);
            MyRibbon.iComponents.Enabled = true;
            Cursor.Current = Cursors.Default;
            detail.ShowDialog(this);
        }

        void iDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            Delete();
        }

        void iClear_ItemClick(object sender, ItemClickEventArgs e)
        {
            ClearContext();
        }

        void iSelectAll_ItemClick(object sender, ItemClickEventArgs e)
        {
            SelectAll();
        }

        void iCopy_ItemClick(object sender, ItemClickEventArgs e)
        {
           Copy();
        }

        void iRefesh_ItemClick(object sender, ItemClickEventArgs e)
        {
            Nap();
        }

        void iCancel_ItemClick(object sender, ItemClickEventArgs e)
        {
            Cancel();
        }

        void iSave_ItemClick(object sender, ItemClickEventArgs e)
        {
           Save();
        }

        void iClose_ItemClick(object sender, ItemClickEventArgs e)
        {
            Close();
        }
        
        frmMain MyRibbon
        {
            get
            {
                return ParentForm as frmMain;
            }
        }

        public void NapInfo()
        {
            //MessageBox.Show("Chao moi nguwowfi");
            mode = EditMode.Load;
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                this.tBL_DONVITableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
                this.tBL_DONVITableAdapter.Fill(this.dsDonVi.TBL_DONVI);
                if (txtDonvi.Text.Length == 0)
                {
                    if (dsDonVi.TBL_DONVI.Count > 0)
                    {
                        txtDonvi.EditValue = MyLogin.Original.iddonvi;
                    }
                }
                this.tBL_loaiTBTableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
                this.tBL_loaiTBTableAdapter.Fill(this.dsLoaiTB.TBL_loaiTB);

                tBL_nhasxTableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
                this.tBL_nhasxTableAdapter.Fill(this.dsNSX.TBL_nhasx);

                this.tBL_TinhtrangTableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
                this.tBL_TinhtrangTableAdapter.Fill(this.dsTinhTrang.TBL_Tinhtrang);

                this.tBL_MucdichTableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
                this.tBL_MucdichTableAdapter.Fill(this.dsMucdich.TBL_Mucdich);

                Nap((int)txtDonvi.EditValue);
                txtDonvi.EditValue = MyLogin.Original.iddonvi;
                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex)
            {

                MyBox.ShowWarning(ex.Message, "Quản lý thiết bị");
            }
            mode = EditMode.None;
        }

        private void Nap(int id)
        {
            mode = EditMode.Load;
            try
            {
                this.tBL_NHACUNGCAPTableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
                this.tBL_NHACUNGCAPTableAdapter.Fill(this.dsNHACUNGCAP.TBL_NHACUNGCAP);

                this.tBL_THIETBITableAdapter.ClearBeforeFill = true;
                this.tBL_THIETBITableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
                this.tBL_THIETBITableAdapter.FillBy(this.dsThietBi.TBL_THIETBI, id);
            }
            catch (Exception ex)
            {
                MyBox.ShowWarning(ex.Message, "Quản lý thiết bị");
            }
            NotSave = false;
            mode = EditMode.None;
        }

        public void Nap()
        {
            if (txtDonvi.EditValue == null) return;
            Nap((int)txtDonvi.EditValue);
        }

        public void SelectAll()
        {
            gbList.SelectAll();
        }

        public void Copy()
        {
            gbList.CopyToClipboard();
        }

        public void ClearContext()
        {
            MaTBCalcEdit.Value = 0;
            MaNCCLookUpEdit.Text = "";
            TenTBTextEdit.Text = "";
            NguyenGiaCalcEdit.Value = 0;
            TgianSDCalcEdit.Value = 0;
            DiaChiIPTextEdit.Text = "";
            MucDichLookUpEdit.Text = "";
            TgianBHCalcEdit.Value = 0;
            DChiBHLookUpEdit.Text = "";
            DiaChiBH.Text = "";
            TinhTrangTextEdit.Text = "";
            NSXTextEdit.Text = "";
            GhiChuMemoEdit.Text = "";


        }

        public void Add()
        {
            //tBLTHIETBIBindingSource.AddNew();
            
        }

        public void Cancel()
        {
            tBLTHIETBIBindingSource.CancelEdit();
            NotSave = false;
            NapInfo();
        }

        bool Check()
        {
            Entity.dsThietBi.TBL_THIETBIDataTable dt = dsThietBi.TBL_THIETBI;
            for (int i = 0; i < dsThietBi.TBL_THIETBI.Rows.Count; i++)
            {
                DataRow dr = dsThietBi.TBL_THIETBI.Rows[i];
                if (dr.RowState != DataRowState.Deleted)
                {
                    if (dr[dt.MaDonViColumn] == DBNull.Value)
                    {
                        MyBox.ShowWarning("Vui lòng chọn đơn vị!", "Quản lý thiết bị");
                        dr.RowError = "Vui lòng chọn đơn vị!";
                        return false;
                    }

                    if (dr[dt.MaLoaiTBColumn] == DBNull.Value)
                    {
                        MyBox.ShowWarning("Vui lòng chọn loại thiết bị!", "Quản lý thiết bị");
                        dr.RowError = "Vui lòng chọn loại thiết bị!";

                        return false;
                    }

                    if (dr[dt.NgaySuDungColumn] == DBNull.Value)
                    {
                        MyBox.ShowWarning("Vui lòng nhập ngày sử dụng!", "Quản lý thiết bị");
                        dr.RowError = "Vui lòng nhập ngày sử dụng!";
                        return false;
                    }

                    if (dr[dt.TinhTrangColumn] == DBNull.Value)
                    {
                        MyBox.ShowWarning("Vui lòng nhập tình trạng sử dụng sử dụng!", "Quản lý thiết bị");
                        dr.RowError = "Vui lòng nhập tình trạng sử dụng sử dụng!";
                        return false;
                    }
                }
            }
            return true;
        }


        public void Save()
        {

            if (!Check()) return;

            mode = EditMode.Update;
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                tBLTHIETBIBindingSource.EndEdit();
                tBL_THIETBITableAdapter.Adapter.RowUpdated += new System.Data.SqlClient.SqlRowUpdatedEventHandler(Adapter_RowUpdated);
                tBL_THIETBITableAdapter.Update(dsThietBi.TBL_THIETBI);
                dsThietBi.TBL_THIETBI.AcceptChanges();
                NotSave = false;
                
            }
            catch (Exception ex)
            {
                MyBox.ShowWarning(ex.Message, "Quản lý thiết bị");
                //throw;
            }
            mode = EditMode.None;
            OnSaveComplete(null);
            Cursor.Current = Cursors.Default;
        }

        void Adapter_RowUpdated(object sender, System.Data.SqlClient.SqlRowUpdatedEventArgs e)
        {
            OnSaveChanging(new SaveChangingEventArgs(e.RowCount,dsThietBi.TBL_THIETBI.Count));
        }

        public void Delete()
        {
            if (!TBL_quyenBL.isThaydoi(EnumComponent.iProvider)) return;
            
            if (MyBox.ShowQuestion("Bạn thật sự muốn xóa không?", "Quản lý thiết bị") == DialogResult.No) return;

            NotSave = true;
            if (gbList.SelectedRowsCount > 0)
            {
                gbList.DeleteSelectedRows();
            }
            else
            {
                gbList.DeleteRow(gbList.FocusedRowHandle);
            }

        }

        public void Clear()
        {
            
        }

        public void Previous()
        {
           gbList.MovePrev();
        }

        public void Next()
        {
            gbList.MoveNext();
        }

        private void frmThietBi_Activated(object sender, EventArgs e)
        {
            frmMain f = (frmMain)ParentForm;
            if (f != null)
            {
                f.IgClose.Visible = true;
                f.iEdit.Visible = true;
                f.igPrint.Visible = false;
                f.iUndo.Visibility = BarItemVisibility.Always;
                f.iCancel.Visibility = BarItemVisibility.Always;
                f.isPrint.Visibility = BarItemVisibility.Always;
                f.iSave.Visibility = BarItemVisibility.Always;
                f.iClose.Visibility = BarItemVisibility.Always;
                f.iRefesh.Visibility = BarItemVisibility.Always;
                f.iNavigate.Visible = true;
                f.iComponents.Visibility = BarItemVisibility.Always;
                f.iEquipHistory.Visibility = BarItemVisibility.Always;
               
                f.IPrevious.Visibility = BarItemVisibility.Always;
                f.INext.Visibility = BarItemVisibility.Always;
                f.iFilter.Visibility = BarItemVisibility.Always;
                f.iDuplicate.Visibility = BarItemVisibility.Always;

                f.iCopy.Visibility = BarItemVisibility.Always;
                f.iSelectAll.Visibility = BarItemVisibility.Always;
                f.iClear.Visibility = BarItemVisibility.Always;
                f.iDelete.Visibility = BarItemVisibility.Always;

                AddEvent();

            }

            NapInfo();
        }

        private void frmThietBi_Deactivate(object sender, EventArgs e)
        {
            frmMain f = (frmMain)ParentForm;
            if (f != null)
            {
                f.IgClose.Visible = false;
                f.iEdit.Visible = false;
                f.iUndo.Visibility = BarItemVisibility.Never;
                f.iCancel.Visibility = BarItemVisibility.Never;
                f.isPrint.Visibility = BarItemVisibility.Never;
                f.igPrint.Visible = false;
                f.iSave.Visibility = BarItemVisibility.Never;
                f.iClose.Visibility = BarItemVisibility.Never;
                f.iRefesh.Visibility = BarItemVisibility.Never;
                f.iNavigate.Visible = false;
                f.iComponents.Visibility = BarItemVisibility.Never;
                f.iEquipHistory.Visibility = BarItemVisibility.Never;
                f.IPrevious.Visibility = BarItemVisibility.Never;
                f.INext.Visibility = BarItemVisibility.Never;
                f.iFilter.Visibility = BarItemVisibility.Never;
                f.iDuplicate.Visibility = BarItemVisibility.Never;

                f.iCopy.Visibility = BarItemVisibility.Never;
                f.iSelectAll.Visibility = BarItemVisibility.Never;
                f.iClear.Visibility = BarItemVisibility.Never;
                f.iDelete.Visibility = BarItemVisibility.Never;


                RemoveEvent();

            }
        }

        private void frmThietBi_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (NotSave)
            {
                var dialogResult = MyBox.ShowSave("Dữ liệu chưa được lưu!\nBạn có muốn lưu lại không?",
                                                  "Quản lý thiết bị");

                if (dialogResult == DialogResult.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
                if (dialogResult == DialogResult.Yes)
                {
                    Save();
                }
            }

            Hide();
            e.Cancel = !Program._exit;
        }


        public enum Column
        {
            None,
            MaTB,
            TenTB,
            Lock
        }

        Column m_Column = new Column();

        private void gbList_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            gbList.ClearColumnErrors();
            if (txtDonvi.Text.Length == 0)
            {
                MyBox.ShowWarning("Vui lòng chọn đơn vị!", "Quản lý thiết bị");
                return;
            }

            // gbList.UpdateCurrentRow();
            if (m_Column == Column.Lock) return;
            if (m_Column == Column.None)
            {
                if (e.Column == colTenTB)// | e.Column == colTenTB)
                {
                    m_Column = Column.MaTB;
                }
            }

            switch (m_Column)
            {
                case Column.None:
                    return;
                case Column.MaTB:
                    m_Column = Column.Lock;
                    gbList.SetRowCellValue(e.RowHandle, colMaDonVi, txtDonvi.EditValue);
                    if (dv != null) gbList.SetRowCellValue(e.RowHandle, colDiaChiIP, dv.IPClass);
                    //gbList.SetRowCellValue(e.RowHandle, colMaTB,TBL_THIETBIDA.NewID((int) txtDonvi.EditValue));
                    m_Column = Column.None;
                    return;
            }
        }

        private void gbList_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            //int rowindex = gbList.GetDataSourceRowIndex(e.RowHandle);
            //if (rowindex < 0 | rowindex > dsThietBi.TBL_THIETBI.Rows.Count)
            //   {
            //       gbList.UpdateCurrentRow();
            //        return;
            //   }
            //if (dsThietBi.TBL_THIETBI.Rows[rowindex].RowState == DataRowState.Added)
            {
               // Save();
            }
        }

        private void gbList_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                Delete();
            }
        }

        private void gbList_DoubleClick(object sender, EventArgs e)
        {
            iEquipHistory_ItemClick(null, null);

        }

        private TBL_DONVI dv;

        private void txtDonvi_EditValueChanged(object sender, EventArgs e)
        {
            if (txtDonvi.EditValue == null) return;
            if (NotSave)
            {
                var dialogResult = MyBox.ShowSave("Dữ liệu chưa được lưu!\nBạn có muốn lưu lại không?",
                                                  "Quản lý thiết bị");

                if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }
                if (dialogResult == DialogResult.Yes)
                {
                    Save();
                }
            }
            NotSave = false;
            TBL_DONVIDA da=new TBL_DONVIDA();
            dv = da.Get((int) txtDonvi.EditValue);
            Nap((int)txtDonvi.EditValue);

        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                //case Keys.Alt | Keys.D:
                //    //MessageBox.Show("You are stupid");
                //    return true;

                //// some more cases...  

                //case Keys.F1:
                //    //ucToolBar_HelpClick(ucBar);
                //    F11Execute();
                //    return true;
                //case Keys.F3:
                //    F3Execute();
                //    return true;
                //case Keys.F4:
                //    F4Execute();
                //    return true;
                case Keys.F5:
                    NapInfo();
                    return true;
                //case Keys.F6:
                //    F9Execute();
                //    return true;
                //case Keys.F7:
                //    F7Execute();
                //    return true;
                //case Keys.F8:
                //    F8Execute();
                //    return true;
                //case Keys.F9:
                //    F9Execute();
                //    return true;
                //case Keys.F11:
                //    F11Execute();
                //    return true;
                //case Keys.F12:
                //    F12Execute();
                //    return true;
                case Keys.Control | Keys.S:
                    Save();
                    return true;
                case Keys.Control | Keys.W:
                    Save();
                    return true;
                case Keys.F2:
                    Save();
                    return true;
                case Keys.Alt | Keys.X:
                    Close();
                    return true;

                case Keys.F10:

                    Close();
                    return true;
            }

            return false;
        }

        private void gbList_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            int rowIndex = e.RowHandle;
            if (rowIndex >= 0)
            {
                rowIndex++;
                e.Info.DisplayText = rowIndex.ToString();
            }
        }

        private void DChiBHLookUpEdit_EditValueChanged(object sender, EventArgs e)
        {
            DiaChiBH.EditValue = DChiBHLookUpEdit.EditValue;
        }

    }
}